<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[
    function add_new_category()
    {
        var url = 'add_category'
        var ps  = 'new_category='+$F('new_category')
        new Ajax.Updater('news_categories',
                          url,
                          {
                              parameters: ps,
                              insertion:Insertion.Top,
                              evalScripts:true
                          }
                        );
    }
    
    function insert_file_from_iframe(href,title,type,id)
    {
        if (type != "img") {
            alert('Sorry only Image files are allowed');
            return false;
        }
        $('news_file_id').value = id;
        Element.update('img_placeholder',
                       "<img src='<?php get_installed_path() ?>/img.php?src="+href+"&w=200' id='news_image' align='absmiddle' />")

    }
    
// ]]>
</script>
<style type="text/css" media="screen">
/* <![CDATA[ */
    #news_categories {
        height: 75px;
        overflow:auto;
    }
    a.active {
        background:  red;
        color: #fff;
        font-weight: bold;
    }
/* ]]> */
</style>

<h1 id='top_edit'><?php if($news->is_loaded()) {echo "Editing";} else {echo"Adding";} ?> News</h1>

<div id='autosave' style='position:absolute'></div>
<?php echo  error_messages_for('news') ?>
<?php echo  form_tag('modify',array('validation'=>'true','id'=>'news_authoring')) ?>
<?php echo  hidden_field('news','id') ?>
<?php echo  hidden_field_tag('go_back_to',$go_back_to) ?>


<div id='tabsmenu'>
    <ul id='tabs'>
        <li><a href="#tab1">Entry</a></li>
        <li><a href="#tab2">Categories and Timestamp</a></li>
        <li><a href="#tab3">Story Image</a></li>
        <li><a href="#tab4">Custom Fields</a></li>
        <li><a href="#tab5">Story Preview</a></li>
    </ul>
</div>


<div id='tab1' class='tab-page'>
    <?php include load_template('_main_form.php') ?>
    
    <div class='section'>
         <p style='text-align:center;padding:0;margin:0'><?php echo  submit_tag('Save and Continue Editing') ?> <?php echo  submit_tag('Save') ?> 
        <?php if (!$news->get('status')) { echo submit_tag('Publish'); }?></p>
    </div>
    
</div>

<div id='tab2' class='tab-page'>
 <?php include load_template('_cat_time.php') ?>
 <div class='section'>
      <p style='text-align:center;padding:0;margin:0'><?php echo  submit_tag('Save and Continue Editing') ?> <?php echo  submit_tag('Save') ?> 
     <?php if (!$news->get('status')) { echo submit_tag('Publish'); }?></p>
 </div>
 
</div>

<div id="tab3" class='tab-page'>
    <?php include load_template('_image.php') ?>    
    <div class='section'>
         <p style='text-align:center;padding:0;margin:0'><?php echo  submit_tag('Save and Continue Editing') ?> <?php echo  submit_tag('Save') ?> 
        <?php if (!$news->get('status')) { echo submit_tag('Publish'); }?></p>
    </div>
    
</div>

<?php echo  end_form_tag() ?>

<div id="tab4" class='tab-page'>
    <?php include load_template('_custom_fields.php') ?>    
</div>

<div id='tab5' class='tab-page'>
    <?php include load_template('_news_preview.php') ?>
</div>



<div class='div-delete' style='margin-top:5px;'>
<?php echo  form_tag('delete') ?>
<?php echo  hidden_field_tag('id',$news->get('id')) ?>
<?php echo  hidden_field_tag('action','delete') ?>
<span style='color:red;font-weight:bold'>Delete This Post?</span>
<?php echo  submit_tag('Delete Post',array('confirm'=>'Are you sure you want to delete this post?','class'=>'submit_delete')) ?>
<?php echo  end_form_tag() ?>
</div>


<?php if ($news->is_loaded() && $news->get('status') == 0 ) {?>
<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[
    new PeriodicalExecuter(function() {
                var url    = '/admin/news/modify'
                if($F('news_title') == "") return;
                tinyMCE.triggerSave();
                var params = Form.serialize($('news_authoring'))+'&commit=Save'
                new Ajax.Updater('autosave',
                                  url,
                                  {
                                      parameters: params,
                                      evalScripts:true,
                                  }
                                );
            },
        60);
// ]]>
</script>

<?php } ?>

<?php if(!$news->is_loaded()) {?>    
    <script type="text/javascript" charset="utf-8">
       // observe the label field and update the name field,
       // but only if the name field is empty.
       $('news_title').observe('keyup', function(event){
           var new_text = $('news_title').value.replace(/[^\d\w_]+/g,'-').toLowerCase();
           $('news_index_name').value = new_text;
       }); 
    </script>    
<?php } ?>